cd ""
clear 
set more off

* wave 2 dataset. 700 observations, without observations identified as low quality by the survey provider leaves 651
use second_wave_raw


gen wave2=1

********************* Big 5 personality traits
local i=1
foreach var of varlist section1a_1-section1g_6 {
	rename `var' BFI2_`i'
	local ++i
	}

* The following questions have the wrong orientation and need to be reversed	
numlist "11 16 26 31 36 51 12 17 22 37 42 47 3 8 23 28 48 58 4 9 24 29 44 49 5 25 30 45 50 55"

foreach i in `r(numlist)' {
		replace BFI2_`i' =-BFI2_`i'+6

		}
	

* facets
* E	
gen sociability=BFI2_1+BFI2_16+BFI2_31+BFI2_46
gen assertiveness=BFI2_6+BFI2_21+BFI2_36+BFI2_51
gen energy=BFI2_11+BFI2_26+BFI2_41+BFI2_56
* A
gen compassion=BFI2_2+BFI2_17+BFI2_32+BFI2_47
gen respectfulness=BFI2_7+BFI2_22+BFI2_37+BFI2_52
gen trust=BFI2_12+BFI2_27+BFI2_42+BFI2_57
* C
gen organization=BFI2_3+BFI2_18+BFI2_33+BFI2_48
gen productiveness=BFI2_8+BFI2_23+BFI2_38+BFI2_53
gen responsibility=BFI2_13+BFI2_28+BFI2_43+BFI2_58
* N
gen anxiety=BFI2_4+BFI2_19+BFI2_34+BFI2_49
gen depression=BFI2_9+BFI2_24+BFI2_39+BFI2_54
gen em_volatily=BFI2_14+BFI2_29+BFI2_44+BFI2_59
* O
gen curiosity=BFI2_10+BFI2_25+BFI2_40+BFI2_55
gen aesthetic_sense=BFI2_5+BFI2_20+BFI2_35+BFI2_50
gen imagination=BFI2_15+BFI2_30+BFI2_45+BFI2_60

gen extrav=sociability+assertiveness+energy
gen agree=compassion+respectfulness+trust
gen consci=organization+productiveness+responsibility
gen neurot=anxiety+depression+em_volatily
gen open=curiosity+aesthetic_sense+imagination

* emotional stability is the inverse of neuroticism 
gen es=-neurot

global traits extrav consci neurot agree open
global facets sociability assertiveness energy organization productiveness responsibility anxiety depression em_volatily compassion respectfulness trust curiosity aesthetic_sense imagination

/*
Domain Scales
Extraversion: 1, 6, 11R, 16R, 21, 26R, 31R, 36R, 41, 46, 51R, 56
Agreeableness: 2, 7, 12R, 17R, 22R, 27, 32, 37R, 42R, 47R, 52, 57
Conscientiousness: 3R, 8R, 13, 18, 23R, 28R, 33, 38, 43, 48R, 53, 58R
Negative Emotionality: 4R, 9R, 14, 19, 24R, 29R, 34, 39, 44R, 49R, 54, 59
Open-Mindedness: 5R, 10, 15, 20, 25R, 30R, 35, 40, 45R, 50R, 55R, 60

Facet Scales
Sociability: 1, 16R, 31R, 46
Assertiveness: 6, 21, 36R, 51R
Energy Level: 11R, 26R, 41, 56
Compassion: 2, 17R, 32, 47R
Respectfulness: 7, 22R, 37R, 52
Trust: 12R, 27, 42R, 57
Organization: 3R, 18, 33, 48R
Productiveness: 8R, 23R, 38, 53
Responsibility: 13, 28R, 43, 58R
Anxiety: 4R, 19, 34, 49R
Depression: 9R, 24R, 39, 54
Emotional Volatility: 14, 29R, 44R, 59
Intellectual Curiosity: 10, 25R, 40, 55R
Aesthetic Sensitivity: 5R, 20, 35, 50R
Creative Imagination: 15, 30R, 45R, 60
*/




*************************************** SOEP personality traits 
local i=1
foreach var of varlist section1h_1-section1h_6 {
	rename `var' SOEP_extra`i'
	local ++i
	}

* only the second extra SOEP question needs to be reversed (the 3 others in the SOEP questions are common to BFI and already reversed above)	
numlist "2"

foreach i in `r(numlist)' {
		replace SOEP_extra`i' =-SOEP_extra`i'+6

		}
		
gen SOEP_e=BFI2_46+BFI2_1+SOEP_extra2
gen SOEP_a=BFI2_37+BFI2_27+SOEP_extra6
gen SOEP_c=SOEP_extra1+BFI2_8+BFI2_38
gen SOEP_n=BFI2_34+SOEP_extra4+BFI2_4
gen SOEP_o=BFI2_60+BFI2_35+SOEP_extra3+SOEP_extra5

* Self-reported BFI reliability: I am someone who is sure that my answers to these questions describe me accurately
rename section1h_7 sure_personality

******************** GPS economic preferences
rename section3a_1 GPS_risk
rename section3b_1 GPS_time
rename section3c_1 GPS_neg_rec_self
rename section3d_1 GPS_neg_rec_other
rename section3e_1 GPS_alt
rename section3f_1 GPS_pos_rec
rename section3g_1 GPS_neg_rec_self2
rename section3h_1 GPS_trust
rename section3j_1 GPS_pres_bias



gen n=_n

*** Time measures:
*Overall time in minutes
gen length_m=length_of_interview/60
gen length_m2=length_m*length_m



******************* Randomization indicators

*** extra incentives
*** extra incentives
gen extra_inc=(randomization_tracker_order==2)
tab extra_inc

gen extra_inc_high=(double_inc_order==2)
tab extra_inc_high


*** whether BFI questions were presented first
gen BFI_first=substr(hidden_tracker_order,1,1)
replace BFI_first="0" if BFI_first=="3"

*** whether GPA or qualitative ability questions were asked first
gen GPA_first=substr(hidden_tracker_order,76,2)
replace GPA_first=substr(hidden_tracker_order,40,2) if BFI_first=="0"
replace GPA_first="1" if GPA_first=="29"
replace GPA_first="0" if GPA_first=="31"

destring BFI_first GPA_first, replace

****************** demographic indicators

rename (q1_1 q2 q3 q4 q5 section5h) (birth_year male country english profession highest_edu )

gen age=2020-birth_year

* (1=AUS, 2=CAN, 3=UK, 4=USA, 5=other). 
replace country=. if country==5

* 5=other
replace english=. if english==5

* (1=high school, 2=college, 3=employed, 4=unemployed, 5=other)
tab profession

* (1: <high school, 2=high schoool, 3=bachelors, 4=masters, 5=other)
tab highest_edu

* for device type: 2=desktop, 4=phone, 5=tablet
gen pc=device_type==2


gen GPA_pct=section5i_1/section5i_2

* 2 is female, 3 is other
replace male=0 if male==2
replace male=. if male==3

**************** qualitative ability questions
rename (section5b_1 section5c_1 section5d_1 section5e_1 section5f_1 section5g_1) (cog_comp cog_write cog_read cog_comm cog_solve cog_math)

egen cognitive=rowtotal(cog_comp-cog_math)

*** the correct answer to the math exercise added in wave 2 is 8
gen cog_ex=0
replace cog_ex=1 if section5i_clone_1==8
 

* Self Reported Overall Reliability: Please indicate on the scale below how reliable are your answers to this survey.
rename section4_1 reliable

* individuals who say their answers are fully reliable
gen rel_max=(reliable==11)

*** life satisfaction indicators

* general LS question 
rename q_hilda_ls_1 LS_gen
* SWLS Life Satisfaction scale based on 5 questions
gen SWLS=(section4a_1+ section4b_1+ section4c_1+ section4d_1+ section4e_1)/5

*** prepare for merging
keep pid wave2 end_date reliable LS_gen GPS* q_mood_beginning_1 q_mood_end_1 sociability assertiveness energy compassion respectfulness trust organization productiveness responsibility anxiety depression em_volatily curiosity aesthetic_sense imagination extrav agree consci neurot open es SOEP_e SOEP_a SOEP_c SOEP_n SOEP_o  n length_m extra_inc extra_inc_high BFI_first GPA_first GPA_pct cognitive SWLS outlier_t outlier_str dynata_outliers pc cog_* BFI2_1-SOEP_extra6 section4* sure_personality birth_year male country profession highest_edu 


foreach var of varlist end_date reliable LS_gen GPS* q_mood_beginning_1 q_mood_end_1 sociability assertiveness energy compassion respectfulness trust organization productiveness responsibility anxiety depression em_volatily curiosity aesthetic_sense imagination extrav agree consci neurot open es SOEP_e SOEP_a SOEP_c SOEP_n SOEP_o  n length_m extra_inc extra_inc_high BFI_first GPA_first GPA_pct cognitive SWLS outlier_t outlier_str dynata_outliers pc cog_* BFI2_1-SOEP_extra6 section4* sure_personality birth_year male country profession highest_edu  {
	rename `var' w2_`var'
	}

sort pid
	
save second_wave_clean, replace



